#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__author__ = "Administrator"
__name__="call_method"
__date__="2016/7/13"
__time__="15:43"
"""
import  threading
class Foo:
    def __init__(self):
        pass

    def __del__(self):
        print '解释器要销毁对象了'

    def Go(self):
        print 'GO'

    def __call__(self):
        print 'call'


f1 = Foo()  # 执行__init__方法，实例化创建对象
f1.Go()
f1()  # 执行类的__call__方法

Foo()()
#相当于下面两步：
f1 = Foo()
f1()

print '###################'
###########
# 线程中调用call方法，不带参数：
class f(object):
    def __init__(self):
        pass
    def __call__(self):
        print 'hello world'

f()()   # 正常调用

t = threading.Thread(target=f())    # 注意调用call方法的写法
t.start()

# 线程中调用call方法，带参数
class s(object):
    def __init__(self,name):
        self.name = name
    def __call__(self):
        print 'hello sssssssssssss',self.name

s1 = threading.Thread(target=s('tom'))
s1.start()

# 线程中调用call方法和apply方法-参数为元祖：
class t(object):
    def __init__(self,name,args):
        self.name = name
        self.args = args
    def __call__(self):
        apply(self.name,self.args)

def loop(a,b):
    print a,b

t1 = threading.Thread(target=t(loop,('hello','ttttttttttttt jon')))
t1.start()


#线程中调用call方法和apply方法-参数为字典：
class a(object):
    def __init__(self,name,args):
        self.name = name
        self.args = args
    def __call__(self):
        apply(self.name,(),self.args)

def lop(aa,bb):
    print aa,bb

a1 = threading.Thread(target=a(lop,{'aa':'hello','bb':'aaaaaaaaaaaaa  lili'}))
a1.start()